import 'dart:convert';

import 'package:flutter_demo/core/common/values/constants.dart';
import 'package:flutter_demo/core/common/values/server.dart';
import 'package:flutter_demo/ui/pages/composite/state.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class CompositeController extends GetxController {
  static CompositeController get to => Get.find();

  late PageState state = PageState.empty;

  //刷新过期时间
  int expirationTime = -1;
  //是否滚动添加数据
  final ifScrolled = Rx<bool>(false);

  final Map<String, double> itemHeightFromType = {
    SHOWTYPE_BANNER: 140.h,
    SHOWTYPE_BALL: 95.h,
    SHOWTYPE_SLIDE_LIST: 213.h,
  };

  void onTap() {}

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onInit() {
    super.onInit();
    getFoundRecList(refresh: true);
  }

  getFoundRecList({required bool refresh}) {
    logger.i("gePageList 加载数据");
    state = PageState.loding;
    update();
    Future.delayed(Duration(milliseconds: 1000), () {
      var map = jsonDecode(
          "{\"components\":[{\"blockCode\":\"1\",\"showType\":\"BALL\",\"extInfo\":[{\"id\":-1,\"iconUrl\":\"http://p1.music.126.net/4DpSgAVpJny4Ewf-Xw_WQQ==/109951163986641971.jpg\",\"name\":\"hello1\"},{\"id\":2,\"iconUrl\":\"http://p1.music.126.net/Shi7cRT1bDhwpVDM7AOFXg==/109951165265330616.jpg\",\"name\":\"hello1\"},{\"id\":3,\"iconUrl\":\"https://p1.music.126.net/uG5p6CnwAHrLqOkaSeRlnA==/109951163986649164.jpg\",\"name\":\"hello1\"},{\"id\":4,\"iconUrl\":\"http://p1.music.126.net/BAOWsqZmmxL8JIH-wejMmQ==/109951167294312390.jpg\",\"name\":\"hello1\"},{\"id\":4,\"iconUrl\":\"http://p1.music.126.net/BAOWsqZmmxL8JIH-wejMmQ==/109951167294312390.jpg\",\"name\":\"hello1\"},{\"id\":4,\"iconUrl\":\"http://p1.music.126.net/BAOWsqZmmxL8JIH-wejMmQ==/109951167294312390.jpg\",\"name\":\"hello1\"},{\"id\":4,\"iconUrl\":\"http://p1.music.126.net/BAOWsqZmmxL8JIH-wejMmQ==/109951167294312390.jpg\",\"name\":\"hello1\"},{\"id\":4,\"iconUrl\":\"http://p1.music.126.net/BAOWsqZmmxL8JIH-wejMmQ==/109951167294312390.jpg\",\"name\":\"hello1\"}]},{\"blockCode\":\"5\",\"showType\":\"BANNER\",\"extInfo\":{\"banner\":[{\"bannerId\":1,\"pic\":\"https://liangcang-material.alicdn.com/prod/upload/03c634de749f44308e5fe380cbdbf968.webp.jpg?x-oss-process=image/resize,w_750/format,webp/interlace,1\",\"title\":\"hello1\"},{\"bannerId\":2,\"pic\":\"https://liangcang-material.alicdn.com/prod/upload/b92aa7f744744d2b8d70c2e820a96509.webp.jpg?x-oss-process=image/resize,w_750/format,webp/interlace,1\",\"title\":\"hello2\"},{\"bannerId\":3,\"pic\":\"https://liangcang-material.alicdn.com/prod/upload/0ae54823bbb64a5392da582739d72a86.webp.jpg?x-oss-process=image/resize,w_750/format,webp/interlace,1\",\"title\":\"hello3\"}]}},{\"blockCode\":\"HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"showType\":\"SLIDE_LIST\",\"dislikeShowType\":0,\"action\":\"orpheus://playlistCollection?referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"uiElement\":{\"subTitle\":{\"title\":\"推荐歌单\"},\"button\":{\"action\":\"orpheus://playlistCollection?referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"text\":\"更多\",\"iconUrl\":null,\"biData\":null},\"rcmdShowType\":\"DEFAULT\"},\"creatives\":[{\"creativeType\":\"scroll_playlist\",\"creativeId\":\"7431834645\",\"action\":\"orpheus://nm/playlist/flow?source=HOMEPAGE_BLOCK_PLAYLIST_RCMD&bizData=[{\\\"resourceId\\\":\\\"7431834645\\\",\\\"alg\\\":\\\"bysong_play_rt\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"2864076078\\\",\\\"alg\\\":\\\"bysong_red_ol\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"6607554676\\\",\\\"alg\\\":\\\"bysong_profile_ol\\\",\\\"reason\\\":null}]&snap=true&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"uiElement\":{\"mainTitle\":{\"title\":\"日落大道｜80's复古科幻的经典美学\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/Wg0rNJ49IbJ4dytHc5bPrQ==/109951167407755902.jpg\"},\"labelTexts\":[\"欧美\",\"怀旧\",\"兴奋\"],\"rcmdShowType\":\"DEFAULT\"},\"resources\":[{\"uiElement\":{\"mainTitle\":{\"title\":\"日落大道｜80's复古科幻的经典美学\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/Wg0rNJ49IbJ4dytHc5bPrQ==/109951167407755902.jpg\"},\"labelTexts\":[\"欧美\",\"怀旧\",\"兴奋\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"7431834645\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":413354,\"highQuality\":false,\"specialType\":0},\"action\":\"orpheus://nm/playlist/flow?source=HOMEPAGE_BLOCK_PLAYLIST_RCMD&bizData=[{\\\"resourceId\\\":\\\"7431834645\\\",\\\"alg\\\":\\\"bysong_play_rt\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"2864076078\\\",\\\"alg\\\":\\\"bysong_red_ol\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"6607554676\\\",\\\"alg\\\":\\\"bysong_profile_ol\\\",\\\"reason\\\":null}]&snap=true&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"bysong_play_rt\",\"logInfo\":\"{\\\"deepScore\\\":\\\"0.0\\\",\\\"cartScore\\\":\\\"0.0\\\",\\\"src\\\":\\\"423314485\\\",\\\"clickScore\\\":\\\"0.0\\\",\\\"pScore\\\":\\\"0.0\\\",\\\"srcType\\\":\\\"bysong\\\"}\",\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null},{\"uiElement\":{\"mainTitle\":{\"title\":\"温柔的晚风和音乐，一定能吹散许多不愉快吧\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/IZLxSLFZNMWpe4qfQcT4wA==/109951164193824137.jpg\"},\"labelTexts\":[\"流行\",\"治愈\",\"民谣\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"2864076078\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":15101579,\"highQuality\":false,\"specialType\":0},\"action\":\"orpheus://nm/playlist/flow?source=HOMEPAGE_BLOCK_PLAYLIST_RCMD&bizData=[{\\\"resourceId\\\":\\\"2864076078\\\",\\\"alg\\\":\\\"bysong_red_ol\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"6607554676\\\",\\\"alg\\\":\\\"bysong_profile_ol\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"7431834645\\\",\\\"alg\\\":\\\"bysong_play_rt\\\",\\\"reason\\\":null}]&snap=true&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"bysong_red_ol\",\"logInfo\":\"{\\\"deepScore\\\":\\\"0.0\\\",\\\"cartScore\\\":\\\"0.0\\\",\\\"src\\\":\\\"34586075\\\",\\\"clickScore\\\":\\\"0.0\\\",\\\"pScore\\\":\\\"0.0\\\",\\\"srcType\\\":\\\"bysong\\\"}\",\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null},{\"uiElement\":{\"mainTitle\":{\"title\":\"以后要在崭新的生活里热爱自己\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/fgOviiPwAO0s2xKyWXTtIg==/109951165712279062.jpg\"},\"labelTexts\":[\"流行\",\"华语\",\"民谣\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"6607554676\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":387423,\"highQuality\":false,\"specialType\":0},\"action\":\"orpheus://nm/playlist/flow?source=HOMEPAGE_BLOCK_PLAYLIST_RCMD&bizData=[{\\\"resourceId\\\":\\\"6607554676\\\",\\\"alg\\\":\\\"bysong_profile_ol\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"7431834645\\\",\\\"alg\\\":\\\"bysong_play_rt\\\",\\\"reason\\\":null},{\\\"resourceId\\\":\\\"2864076078\\\",\\\"alg\\\":\\\"bysong_red_ol\\\",\\\"reason\\\":null}]&snap=true&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"bysong_profile_ol\",\"logInfo\":\"{\\\"deepScore\\\":\\\"0.0\\\",\\\"cartScore\\\":\\\"0.0\\\",\\\"src\\\":\\\"1990544748\\\",\\\"clickScore\\\":\\\"0.0\\\",\\\"pScore\\\":\\\"0.0\\\",\\\"srcType\\\":\\\"bysong\\\"}\",\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null}],\"alg\":\"bysong_play_rt\",\"logInfo\":\"{\\\"deepScore\\\":\\\"0.0\\\",\\\"cartScore\\\":\\\"0.0\\\",\\\"src\\\":\\\"423314485\\\",\\\"clickScore\\\":\\\"0.0\\\",\\\"pScore\\\":\\\"0.0\\\",\\\"srcType\\\":\\\"bysong\\\"}\",\"position\":0},{\"creativeType\":\"list\",\"creativeId\":\"117377955\",\"action\":\"orpheus://playlist/117377955?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"uiElement\":{\"mainTitle\":{\"title\":\"【欧美男团】秒杀耳朵系列\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/FJAxNkFoq3dGiS9tz_bGgQ==/3405187512421439.jpg\"},\"labelTexts\":[\"欧美\",\"流行\",\"摇滚\"],\"rcmdShowType\":\"DEFAULT\"},\"resources\":[{\"uiElement\":{\"mainTitle\":{\"title\":\"【欧美男团】秒杀耳朵系列\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/FJAxNkFoq3dGiS9tz_bGgQ==/3405187512421439.jpg\"},\"labelTexts\":[\"欧美\",\"流行\",\"摇滚\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"117377955\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":137835472,\"highQuality\":false,\"specialType\":0},\"action\":\"orpheus://playlist/117377955?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"alg_doudi\",\"logInfo\":null,\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null}],\"alg\":\"alg_doudi\",\"position\":0},{\"creativeType\":\"list\",\"creativeId\":\"310970433\",\"action\":\"orpheus://playlist/310970433?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"uiElement\":{\"mainTitle\":{\"title\":\"【旋律控】超级好听的欧美良曲\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/2MsstS-M9w5-li0aRy3sUQ==/1380986606815861.jpg\"},\"labelTexts\":[\"欧美\",\"流行\",\"经典\"],\"rcmdShowType\":\"DEFAULT\"},\"resources\":[{\"uiElement\":{\"mainTitle\":{\"title\":\" 【旋律控】超级好听的欧美良曲\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/2MsstS-M9w5-li0aRy3sUQ==/1380986606815861.jpg\"},\"labelTexts\":[\"欧美\",\"流行\",\"经典\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"310970433\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":480888992,\"highQuality\":false,\"specialType\":0},\"action\":\"orpheus://playlist/310970433?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"alg_doudi\",\"logInfo\":null,\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null}],\"alg\":\"alg_doudi\",\"position\":0},{\"creativeType\":\"list\",\"creativeId\":\"37432514\",\"action\":\"orpheus://playlist/37432514?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"uiElement\":{\"mainTitle\":{\"title\":\"那些只听前奏就中毒的英文歌\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/mQy3lRj6YJ0TW3fM9v85YA==/6643249256145165.jpg\"},\"labelTexts\":[\"流行\",\"欧美\",\"快乐\"],\"rcmdShowType\":\"DEFAULT\"},\"resources\":[{\"uiElement\":{\"mainTitle\":{\"title\":\"那些只听前奏就中毒的英文歌\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/mQy3lRj6YJ0TW3fM9v85YA==/6643249256145165.jpg\"},\"labelTexts\":[\"流行\",\"欧美\",\"快乐\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"37432514\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":191408176,\"highQuality\":true,\"specialType\":0},\"action\":\"orpheus://playlist/37432514?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"alg_doudi\",\"logInfo\":null,\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null}],\"alg\":\"alg_doudi\",\"position\":0},{\"creativeType\":\"list\",\"creativeId\":\"360062344\",\"action\":\"orpheus://playlist/360062344?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"uiElement\":{\"mainTitle\":{\"title\":\"世界上很好听的纯音乐（经典不朽）\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/92NWlGo76ha-if-WMK3vCg==/1410673428769729.jpg\"},\"labelTexts\":[\"轻音乐\",\"钢琴\",\"世界音乐\"],\"rcmdShowType\":\"DEFAULT\"},\"resources\":[{\"uiElement\":{\"mainTitle\":{\"title\":\"世界上很好听的纯音乐（经典不朽）\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/92NWlGo76ha-if-WMK3vCg==/1410673428769729.jpg\"},\"labelTexts\":[\"轻音乐\",\"钢琴\",\"世界音乐\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"360062344\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":129503488,\"highQuality\":false,\"specialType\":0},\"action\":\"orpheus://playlist/360062344?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"alg_doudi\",\"logInfo\":null,\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null}],\"alg\":\"alg_doudi\",\"position\":0},{\"creativeType\":\"list\",\"creativeId\":\"306397077\",\"action\":\"orpheus://playlist/306397077?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"uiElement\":{\"mainTitle\":{\"title\":\"【节奏控】那些超带感的音乐\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/RnOZHM0BNxXuy-RwQQI5BA==/3313928048221849.jpg\"},\"labelTexts\":[\"欧美\",\"流行\",\"电子\"],\"rcmdShowType\":\"DEFAULT\"},\"resources\":[{\"uiElement\":{\"mainTitle\":{\"title\":\"【节奏控】那些超带感的音乐\"},\"subTitle\":{\"title\":\"\"},\"image\":{\"imageUrl\":\"http://p1.music.126.net/RnOZHM0BNxXuy-RwQQI5BA==/3313928048221849.jpg\"},\"labelTexts\":[\"欧美\",\"流行\",\"电子\"],\"rcmdShowType\":\"DEFAULT\"},\"resourceType\":\"list\",\"resourceState\":null,\"resourceId\":\"306397077\",\"resourceUrl\":null,\"resourceExtInfo\":{\"playCount\":293220992,\"highQuality\":false,\"specialType\":0},\"action\":\"orpheus://playlist/306397077?autoplay=0&referLog=HOMEPAGE_BLOCK_PLAYLIST_RCMD\",\"actionType\":\"orpheus\",\"valid\":true,\"alg\":\"alg_doudi\",\"logInfo\":null,\"ctrp\":null,\"likedCount\":null,\"replyCount\":null,\"resourceContentList\":null,\"position\":null,\"playParams\":null}],\"alg\":\"alg_doudi\",\"position\":0}],\"canClose\":false,\"blockStyle\":0,\"canFeedback\":false,\"blockDemote\":false,\"sort\":0},{\"blockCode\":\"8\",\"showType\":\"LIST\"},{\"blockCode\":\"9\",\"showType\":\"LIST\"},{\"blockCode\":\"10\",\"showType\":\"LIST\"},{\"blockCode\":\"11\",\"showType\":\"LIST\"},{\"blockCode\":\"12\",\"showType\":\"LIST\"}]}");
      state = PageState.fromJson(map);
      update();
    });
  }
  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
